package com.example.spingioc.controller;

import com.example.spingioc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller
public class UserController {
    @Autowired
    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }


    //依赖注入的三种方法

//     1.属性注入
//    @Autowired
//    private UserService userService;


//    2.构造方法注入
//    private UserService userService;
//    public UserController() {
//    }
//    @Autowired  //指定默认用有参数的构造方法
//    public UserController(UserService userService) {
//        this.userService = userService;
//    }



//    //2.setter方法注入
//    private UserService userService;
//    @Autowired
//    public void setUserService(UserService userService) {
//        this.userService = userService;
//    }



    public void say(){
        System.out.println("UserContrller say...");
        userService.say();
    }
}
